package com.axjy.service.impl;

import com.axjy.mapper.UserMapper;
import com.axjy.pojo.User;
import com.axjy.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public List<User> search(String username) {
        QueryWrapper<User> wrapper= Wrappers.query();
        wrapper.like(!StringUtils.isBlank(username),"username",username);
        return userMapper.selectList(wrapper);
    }

    public Page<User> search(String username,int current,int size){
        QueryWrapper<User> wrapper= Wrappers.query();
        wrapper.like("username",username);
        Page<User> page=new Page<>(current,size);
        return userMapper.selectPage(page,wrapper);
    }


    public User searchByUserCode(String userCode){
        QueryWrapper<User> wrapper=Wrappers.query();
        wrapper.eq("user_code",userCode);
        return userMapper.selectOne(wrapper);
    }

}
